package com.cl.template.jdk;

import java.util.Objects;

public class Duck implements Comparable<Duck> {
    String name;
    Integer weight;

    public Duck(String name, Integer weight) {
        this.name = name;
        this.weight = weight;
    }

    @Override
    public String toString() {
        return "Duck{" +
                "name='" + name + '\'' +
                ", weight=" + weight +
                '}';
    }

    @Override
    public int compareTo(Duck o) {
        if (o == null) {
            return 1;
        } else if (this.weight < o.weight) {
            return -1;
        } else if (Objects.equals(this.weight, o.weight)) {
            return 0;
        } else {
            return 1;
        }
    }
}
